%% volToArea_v2_0
%  Version 2.0
%  Author: Adeyinka Lesi
%  Date: 3/24/20
%  Project: Tumor Growth, Logarithmic Continuum Form
%  volToArea is meant to convert cell area to volume
%  area: float; cell area from experiment
%  vol: float; approximate cell volume
%  [vol] = volToArea_v2_0(area)
%% Version History
%  2.0: separating fL_cell into multiple constants to clarify and adding a
%  thickness limit to tumors are assumed to be more of an ellipsoid

function [area] = volToArea_v2_0(vol)

um_px = (4/1388+3/1040)/2*1e4; %alternatively, um_px = sqrt(4*3*(1e8)/1388/1040)
fL_cell =  4/3*pi*5^3; % diameter of cancer cell = 10 um
shape_factor = 4/3/sqrt(pi); % value assumes sphere
calib_factor = 1/10; % *needs calibration
cell_px3 = um_px^3/fL_cell;
thick_limit = 0.4*1e4/um_px; % assuming tumor thickness limit of 0.5 cm

area = zeros(size(vol));
for i = 1:length(vol)
    thick_term = vol(i)*sqrt(1/pi)/thick_limit;
    % need to solve cubic
    C = [cell_px3*shape_factor*calib_factor 0 -thick_term -vol(i)];
    all_sols = roots(C);
    real_sols = all_sols(imag(all_sols)==0&real(all_sols)>=0);
    area(i) = real_sols(1)^2;
end

